package cn.edu.wfit.modules.learn.controller.coursemanagement;

import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.web.page.TableDataInfo;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;
import cn.edu.wfit.modules.learn.domain.WfitStage;
import cn.edu.wfit.modules.learn.service.coursemangement.IWfitStageService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 阶段Controller
 *
 * @author ruoyi
 * @date 2025-07-18
 */
@RestController
@RequestMapping("/stage")
public class WfitStageController extends BaseController {
    @Autowired
    private IWfitStageService wfitStageService;

    /**
     * 查询阶段列表
     */
    @RequiresPermissions("system:stage:list")
    @GetMapping("/list")
    public TableDataInfo list(WfitStage wfitStage) {
        startPage();
        List<WfitStage> list = wfitStageService.selectWfitStageList(wfitStage);
        return getDataTable(list);
    }

    @GetMapping("/stage/{courseid}")
    public AjaxResult list(@PathVariable("courseid") Long courseid) {
        List<WfitStage> list = wfitStageService.selectStageListByCourseId(courseid);
        return success(list);
    }

    /**
     * 导出阶段列表
     */
    @RequiresPermissions("system:stage:export")
    @Log(title = "阶段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfitStage wfitStage) {
        List<WfitStage> list = wfitStageService.selectWfitStageList(wfitStage);
        ExcelUtil<WfitStage> util = new ExcelUtil<WfitStage>(WfitStage.class);
        util.exportExcel(response, list, "阶段数据");
    }

    /**
     * 获取阶段详细信息
     */
    @RequiresPermissions("system:stage:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wfitStageService.selectWfitStageById(id));
    }

    /**
     * 新增阶段
     */
    @RequiresPermissions("system:stage:add")
    @Log(title = "阶段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfitStage wfitStage) {
        return toAjax(wfitStageService.insertWfitStage(wfitStage));
    }

    /**
     * 修改阶段
     */
    @RequiresPermissions("system:stage:edit")
    @Log(title = "阶段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfitStage wfitStage) {
        return toAjax(wfitStageService.updateWfitStage(wfitStage));
    }

    /**
     * 删除阶段
     */
    @RequiresPermissions("system:stage:remove")
    @Log(title = "阶段", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wfitStageService.deleteWfitStageByIds(ids));
    }
}
